﻿using System;
namespace Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="pais2", Namespace="http://producers.taitis.xtee.riik.ee/producer/taitis", Target=typeof(Pais2))]
    public class Pais2Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IPais2 clazz;
        
        public Pais2Serializer(IPais2 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("asutus");
            if (clazz.Asutus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Asutus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Asutus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("andmekogu");
            if (clazz.Andmekogu!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Andmekogu))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Andmekogu");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("ametnik");
            if (clazz.Ametnik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Ametnik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Ametnik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("id");
            if (clazz.Id!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Id))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Id");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("nimi");
            if (clazz.Nimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Nimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("autentija");
            if (clazz.Autentija!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Autentija))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Autentija");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("ametniknimi");
            if (clazz.Ametniknimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Ametniknimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Ametniknimi");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "asutus")) {
                goto asutus;
            }
            else {
                if ((Reader.LocalName == "andmekogu")) {
                    goto andmekogu;
                }
                else {
                    if ((Reader.LocalName == "ametnik")) {
                        goto ametnik;
                    }
                    else {
                        if ((Reader.LocalName == "id")) {
                            goto id;
                        }
                        else {
                            if ((Reader.LocalName == "nimi")) {
                                goto nimi;
                            }
                            else {
                                if ((Reader.LocalName == "autentija")) {
                                    goto autentija;
                                }
                                else {
                                    if ((Reader.LocalName == "ametniknimi")) {
                                        goto ametniknimi;
                                    }
                                    else {
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        asutus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>pais2>asutus");
            }
            clazz.Asutus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("asutus")).Value;
            goto START;
        andmekogu:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>pais2>andmekogu");
            }
            clazz.Andmekogu = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("andmekogu")).Value;
            goto START;
        ametnik:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>pais2>ametnik");
            }
            clazz.Ametnik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ametnik")).Value;
            goto START;
        id:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>pais2>id");
            }
            clazz.Id = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("id")).Value;
            goto START;
        nimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>pais2>nimi");
            }
            clazz.Nimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("nimi")).Value;
            goto START;
        autentija:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>pais2>autentija");
            }
            clazz.Autentija = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("autentija")).Value;
            goto START;
        ametniknimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>pais2>ametniknimi");
            }
            clazz.Ametniknimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ametniknimi")).Value;
            goto START;
        }
    }
}
